package hu.tortavar2.client.view.product;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.HeadingElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.dom.client.UListElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class ProductItemDetailView extends Composite {

	private static ProductItemDetailViewUiBinder uiBinder = GWT
			.create(ProductItemDetailViewUiBinder.class);

	interface ProductItemDetailViewUiBinder extends
			UiBinder<Widget, ProductItemDetailView> {
	}

	public ProductItemDetailView() {
		initWidget(uiBinder.createAndBindUi(this));
		like.setAttribute("data-href", Window.Location.getHref());

	}

	@UiField HTMLPanel grid_01;
	@UiField HTMLPanel ribbon_02;
	@UiField HTMLPanel prodBox02;
	@UiField HTMLPanel text_box;
	
	@UiField Image image;
	@UiField Label desc;
	@UiField Anchor backButton;
	
	@UiField UListElement desc_extra_list;
	@UiField HeadingElement title;
	@UiField SpanElement price;
	@UiField SpanElement whereToBuy;
	@UiField DivElement like;
	
	@UiHandler("backButton")
		void onClickBackButton(ClickEvent e) {
			History.back();
		}

	public void setProductName(String productName) {
		this.title.setInnerText(productName);
		//this.title.setAttribute("property", "og:title");
	}
	
	public String getProductName() {
		return this.title.getInnerText();
	}
	
	public void setProductPrice(String price) {
		this.price.setInnerText(price);
	}
	
	public void setProductRibbon(String ribbonType) {
		this.ribbon_02.addStyleName(ribbonType);
	}
	
	public void setWhereToBuy(String whereToBuy) {
		this.whereToBuy.setInnerText(whereToBuy);
	}
	
	public void setProductImageUrl(String url) {
		this.image.setUrl(url);
	}
	
	public String getProductImageUrl() {
		return this.image.getUrl();
	}
	
	public void setProductDescription(String desciption) {
		this.desc.setText(desciption);
	}
	
	public void setDescExtra(List<String> descExtra) {
		if (descExtra.size() > 0) {
			Element h5 = DOM.createElement("h5");
			h5.setInnerText("Részletek");
			text_box.getElement().insertBefore(h5, desc_extra_list);
		}
		
		for(String elem : descExtra){
			Element li = DOM.createElement("li");
			li.setInnerText(elem);
			desc_extra_list.appendChild(li);
		}
	}
}
